package com.zhiying.controller;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.zhiying.config.StatusEnum;
import com.zhiying.domain.CMS_Organization;
import com.zhiying.domain.CMS_User;
import com.zhiying.domain.Role;
import com.zhiying.domain.UserLoginLog;
import com.zhiying.mybatis.UserMapper;
import com.zhiying.page.BasePageDTO;
import com.zhiying.page.CmsPageResult;
import com.zhiying.page.CmsResult;
import com.zhiying.page.PageInfo;
import com.zhiying.page.UserPageDTO;
import com.zhiying.service.LoginService;
import com.zhiying.service.MenuService;
import com.zhiying.until.RegexUtils;
import com.zhiying.until.code.CommonReturnCode;
import com.zhiying.until.ipadderss.IpAddress;


@Controller
@RequestMapping(value = "/administrator/list")
public class AdministratorListController {


	@Autowired
	MenuService  menuService;

	//	@Autowired
	//	MenuJPA menu;
	@Autowired
	private LoginService loginService;

	@Autowired
	UserMapper userMapper;
	//	
	//	@Autowired
	//	private IUserService userService;
	//	@Autowired
	//	private IRoleService roleService;
	//	@Autowired
	//	private IUserRoleService userRoleService;
	//	@Autowired
	//	private IUserLoginLogService userLoginLogService;
	//	@Autowired
	//	private IOrganizationService organizationService;
	//	
	/**
	 * GET 管理员列表
	 * @return
	 */
	@RequiresPermissions("administrator:info:view")
	@GetMapping(value = "/")
	@ResponseBody
	public Object listUser(PageInfo pageInfo, @RequestParam(required = false, value = "search") String search) {
		UserPageDTO userPageDTO = menuService.selectByPage(pageInfo, search);
		return new CmsPageResult(userPageDTO.getUserVOs(), userPageDTO.getPageInfo().getTotal());
	}
	/**
	 * GET 管理员登录日志列表页面
	 * @return
	 */
	@RequiresPermissions("administrator:list:view")
	@RequestMapping("/view")
	public String getPage() {

		return "/admin/admin_user_list";

	}


	/**
	 * DELETE 删除管理员
	 * @return
	 */
	@RequiresPermissions("administrator:list:delete")
	@DeleteMapping(value = "/{userId}")
	@ResponseBody
	public Object delete(@PathVariable("userId") Long userId) {
		//AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
		/*if (authorizingUser != null) {*/
		Integer count = menuService.deleteUserByUserId(userId);
		return new CmsResult(CommonReturnCode.SUCCESS, count);
		/*} else {*/
		/*	return new CmsResult(CommonReturnCode.UNAUTHORIZED*/
	}
	/**
	 * GET 更新管理员页面
	 * @return
	 */
	@RequiresPermissions("administrator:list:edit")
	@GetMapping(value = "/{userId}/edit")
	public String getUpdatePage(Model model, @PathVariable("userId") Long userId) {
		//		// 用户信息
		CMS_User user = menuService.selectUserById(userId);
		System.out.println(user.getStatus());
		model.addAttribute("user", user);
		//
		//		// 用户权限
		List<Role> roles = menuService.selectRoleList(StatusEnum.NORMAL.getStatus() );
		model.addAttribute("roles", roles);
		//
		//		// 组织列表
		List<CMS_Organization> organizations = menuService.listBySataus(StatusEnum.NORMAL.getStatus());
		model.addAttribute("organizations", organizations);
		//
		//		// 分配角色
		List<Role> userRoles = menuService.listByUserId( StatusEnum.NORMAL.getStatus(),user.getUserId());
		model.addAttribute("userRoles", userRoles);

		return "/admin/admin_user_update";
	}
	/**
	 * PUT 更新管理员信息
	 * @return
	 */
	@RequiresPermissions("administrator:list:edit")
	@PutMapping(value = "/{userId}")
	@ResponseBody
	public Object update(CMS_User user, @PathVariable("userId") int userId,
			@RequestParam(required = false, value = "roleId") String[] roleIds,HttpServletRequest req) {
		if (!RegexUtils.isEmail(user.getEmail())) {
			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的电子邮箱!");
		}
		if (!RegexUtils.isTelephone(user.getTelephone())) {
			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的手机号码!");
		}

		//		if (authorizingUser != null) {
		// 更新用户及角色记录
		menuService.deleteUserRole(userId);
		int org_id=Integer.valueOf(req.getParameter("organizationId"));
		Integer count = menuService.updateUserById(user,roleIds,org_id);
		return new CmsResult(CommonReturnCode.SUCCESS, count);
		//		} else {
		//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
		//		}
	}

	/**
	 * PUT 启用/冻结管理员
	 * @return
	 */
	@RequiresPermissions("administrator:list:audit")
	@PutMapping(value = "/{userId}/audit")
	@ResponseBody
	public Object audit(@PathVariable("userId") Long userId) {
		/* AuthorizingUser authorizingUser = SingletonLoginUtils.getUser(); */
		/*if (authorizingUser != null) {*/
		CMS_User user=new CMS_User();
		user.setUserId(userId);
		Integer count = menuService.updateStatus(user);
		return new CmsResult(CommonReturnCode.SUCCESS, count);
		/*
		 * } else { return new CmsResult(CommonReturnCode.UNAUTHORIZED); }
		 */
	}

	/**
	 * GET 管理员登录日志列表页面
	 * @return
	 */
	@RequiresPermissions("administrator:list:view")
	@GetMapping(value = "/{userId}/log")
	public String getLogPage(Model model, @PathVariable("userId") Long userId) {
		model.addAttribute("userId", userId);
		return "/admin/admin_user_login_log";
	}

	/**
	 * GET 管理员登录日志列表
	 * @return
	 */
	@RequiresPermissions("administrator:list:view")
	@GetMapping(value = "/{userId}/logs")
	@ResponseBody
	public Object listLogs(@PathVariable("userId") Long userId, PageInfo pageInfo,
			@RequestParam(required = false, value = "search") String search) {

		BasePageDTO<UserLoginLog> basePageDTO = menuService.listByPage(userId, pageInfo, search);
		//Page<UserVO> page = new Page<>(pageInfo.getCurrent(), pageInfo.getLimit());
		//pageInfo.setTotal(menuService.selectCMSUserLoginLog(userId));
		/*
		 * List<UserLoginLog> log=new ArrayList<UserLoginLog>(); UserLoginLog
		 * loginLog=new UserLoginLog(); loginLog.setBrowser("dasd");
		 * loginLog.setLogId(Long.valueOf(1)); loginLog.setLoginTime(new Date());
		 * loginLog.setOperatingSystem("adasfa"); loginLog.setUserId(Long.valueOf(1));
		 * loginLog.setUserIp("gg"); log.add(loginLog);
		 */
		return new CmsPageResult(basePageDTO.getList(), basePageDTO.getPageInfo().getTotal());

	}


	@RequiresPermissions("administrator:list:create")
	@GetMapping(value = "/create")
	public String getInsertPage(Model model) {
		// 用户权限
		List<Role> roles = menuService.selectRoleList(StatusEnum.NORMAL.getStatus());
		model.addAttribute("roles", roles);
		//		// 组织列表
		List<CMS_Organization> organizations = menuService.listBySataus(StatusEnum.NORMAL.getStatus());
		model.addAttribute("organizations", organizations);
		return "/admin/admin_user_create";
	}

	@RequiresPermissions("administrator:list:create")
	@PostMapping(value = "")
	@ResponseBody
	public Object insert(CMS_User user 
			,@RequestParam("file") MultipartFile file,HttpServletRequest req,HttpServletResponse resp) {
		String[] array = req.getParameterValues("arr");
		//获取角色字符串
		String[]roleid=null;
		//使用数组储存角色id
		String arrayStr=null;
		for(String str : array) {
			System.out.println(str);
			arrayStr=str;
		}
		if(arrayStr.length()==1) {
			roleid=new String[1];
			roleid[0]=arrayStr;
		}else {
			String []ay=arrayStr.split(",");
			roleid=new String[ay.length];
			//初始化数组
			for(int i=0;i<ay.length;i++) {
				roleid[i]=ay[i];
			}

		}
		CMS_User user1=loginService.getUserInfoByUserName(user.getLoginName());

		if(user1!=null) { return new
				CmsResult(CommonReturnCode.UserRepetitions.getCode(), "用户名已存在!"); } 
		if(!RegexUtils.isEmail(user.getEmail())) { return new
				CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的电子邮箱!"); } 
		if(!RegexUtils.isTelephone(user.getTelephone())) { return new
				CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的手机号码!"); }
		String fileName = file.getOriginalFilename();
		System.out.println(fileName);
		System.out.println(req.getParameter("loginName"));
		String uploadPath = req.getSession().getServletContext().getRealPath("default/avatar/");
		File dest = new File("src/main/resources/static/default/avatar/"+fileName);
		int organizationId=Integer.valueOf(req.getParameter("organizationId"));
		CMS_User users=loginService.getUserInfoByUserName((String)SecurityUtils.getSubject().getSession().getAttribute("loginName"));
		CMS_User cmsUser=new CMS_User();
		cmsUser.setUserName(req.getParameter("userName"));
		cmsUser.setAge(12);
		cmsUser.setCreateBy(users.getUserName());
		cmsUser.setCreateTime(new Date());
		cmsUser.setEmail(req.getParameter("email"));
		cmsUser.setLastLoginIp(IpAddress.getIpAddr(req));
		cmsUser.setLastLoginTime(new Date());
		cmsUser.setLoginName(req.getParameter("loginName"));
		ByteSource credentialsSalt = ByteSource.Util.bytes(req.getParameter("loginName"));
		Object obj = new SimpleHash("MD5", req.getParameter("loginPassword"), credentialsSalt, 6);
		System.out.println(obj.toString());
		cmsUser.setLoginPassword(obj.toString());
		cmsUser.setPicImg("default/avatar/"+fileName);
		cmsUser.setRealName(req.getParameter("realName"));
		cmsUser.setSalt(credentialsSalt.toString());
		cmsUser.setSex(Integer.valueOf(req.getParameter("sex")));
		cmsUser.setStatus(Integer.valueOf(req.getParameter("status")));
		cmsUser.setTelephone(req.getParameter("telephone"));
		cmsUser.setUserName(req.getParameter("userName"));
		cmsUser.setUpdateBy(users.getUserName());
		cmsUser.setUpdateTime(new Date());
		menuService.insertNewUser(cmsUser, organizationId, roleid);
		try {
			FileOutputStream fos=new FileOutputStream(dest);
			fos.write(file.getBytes());
			fos.flush();
			fos.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


		//		HttpServletRequest request=((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		//		DiskFileItemFactory factory = new DiskFileItemFactory();
		//
		//		//创建文件上传对象
		//		ServletFileUpload upload = new ServletFileUpload(factory);
		//
		//		//WebRoot下upload文件夹在操作系统中磁盘的路径
		//		String uploadPath = request.getSession().getServletContext().getRealPath("images/avatar/");

		//		if(ServletFileUpload.isMultipartContent(request)){
		//
		//			try {
		//				List<FileItem> list = upload.parseRequest(request);
		//
		//				for(FileItem item:list){
		//
		//					if(item.isFormField()){
		//						//普通表单
		//					}else {
		//						String fileName = item.getName();
		//						System.out.println(fileName);
		//					}
		//				}
		//			} catch (FileUploadException e) {
		//				// TODO Auto-generated catch block
		//				e.printStackTrace();
		//			}
		//
		//		}


		//			AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
		//			if (authorizingUser != null) {
		//				try {
		// 创建用户及插入角色记录
		//Integer count = userService.insertUser(user, roleIds, authorizingUser.getUserName());
		return new CmsResult(CommonReturnCode.SUCCESS, 1);
		//				}catch (ValidateException e) {
		//					logger.error(e.getMessage(), e);
		//					return new CmsResult(e.getCode(), e.getMessage());
		//}
		//			}else{
		//				return new CmsResult(CommonReturnCode.UNAUTHORIZED);
		//			}
	}


	public void httpUpload(String murl,MultipartFile file){  
		String boundary="-------------------------7e020233150564";//编节符  
		String prefix="--";//前缀 上传时需要多出两个-- 一定需要注意！！！  
		String end="\r\n";//这里也需要注意，在html协议中，用 “/r/n” 换行，而不是 “/n”。  

		SimpleDateFormat adf=new SimpleDateFormat("HHmmss");//通过时间来创建文件名  
		String uploadname=adf.format(new Date())+".jpg";//上传的文件名称  
		System.out.println(uploadname);
		try {  
			URL http=new URL(murl);  
			HttpURLConnection conn= (HttpURLConnection) http.openConnection();  
			conn.setRequestMethod("POST");  
			conn.setReadTimeout(50000000);  
			conn.setDoInput(true);//准许向服务器读数据  
			conn.setDoOutput(true);//准许向服务器写入数据  

			/*设置向服务器上传数据的请求方式  默认的是表单形式 
			 * 通过Content-Type协议向服务器上传数据 
			 * boundary 
			 * */  
			conn.setRequestProperty("Content-Type","multipart/form-data;boundary="+boundary);  

			//创建一个输出流对象，  
			DataOutputStream out=new DataOutputStream(conn.getOutputStream());  
			/* 
			 * 
              -----------------------------7e020233150564 
              Content-Disposition: form-data; name="file"; filename="I:\迅雷下载\18fb1f51c9eb63489cce9e029154782e.jpg" 
              Content-Type: image/jpeg 
                                        //这里是空一行  需要注意 
              <二进制文件数据未显示> 
              ---------------------------7e020233150564-- 
			 */  
			//向服务器写入数据  这里就需要完全根据以上协议格式来写，需要仔细，避免出错。  
			out.writeBytes(prefix+boundary+end);//这是第一行  并回车换行  
			//这是第二行，文件名和对应服务器的  
			out.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\""+uploadname+"\""+end);//这是第二行  
			out.writeBytes(end);//空一行  
			//以下写入图片  
			//            FileInputStream fileInputStream=new FileInputStream(new File(mfilename));  
			//            byte[]b=new byte[1024*4];//缓冲区  
			//            int len;  
			//            //循环读数据  
			//            while((len=fileInputStream.read(b))!=-1){  
			//                out.write(b, 0, len);  
			//            }  
			out.write(file.getBytes());
			//写完数据后 回车换行  
			out.writeBytes(end);  
			out.writeBytes(prefix + boundary + prefix + end);  
			out.flush();//清空  

			//创建一个输入流对象  获取返回的信息  是否上传成功  
			//            BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));  
			//            StringBuffer sb=new StringBuffer();  
			//            String str;  
			//            while((str=reader.readLine())!=null){  
			//                sb.append(str);  
			//            }  
			//            //关闭流信息  
			//            if(out!=null)out.close();  
			//            if(reader!=null)reader.close();  

			// System.out.print("返回结果："+sb.toString());  
		} catch (MalformedURLException e) {  
			e.printStackTrace();  
		} catch (IOException e) {  
			e.printStackTrace();  
		}  

	} 
	
	/**
	 * GET 个人资料
	 * @return
	 */
	@RequiresPermissions("administrator:list:view")
	@GetMapping(value = "/{userId}")
	public String detail(Model model, @PathVariable  Long userId){
		// 用户信息
		CMS_User user = menuService.selectUserById(userId);
		model.addAttribute("user", user);
		
		// 分配角色
		List<Role> roles = userMapper.listByUserIds(StatusEnum.NORMAL.getStatus(), user.getUserId());
		model.addAttribute("roles", roles);// 用户权限
		
		return "/admin/admin_user_message";
	}

}



//	
//	/**
//	 * GET 管理员列表
//	 * @return
//	 */
//	@ApiOperation(value = "获取管理员列表", notes = "根据分页信息/搜索内容获取管理员列表")  
//	@RequiresPermissions("administrator:info:view")
//	@GetMapping(value = "/")
//	@ResponseBody
//	public Object listUser(PageInfo pageInfo, @RequestParam(required = false, value = "search") String search) {
//		UserPageDTO userPageDTO = userService.listByPage(pageInfo, search);
//		return new CmsPageResult(userPageDTO.getUserVOs(), userPageDTO.getPageInfo().getTotal());
//	}
//	
//	/**
//	 * GET 个人资料
//	 * @return
//	 */
//	@ApiOperation(value = "获取管理员个人资料", notes = "根据url管理员ID获取管理员个人资料")
//	@RequiresPermissions("administrator:list:view")
//	@GetMapping(value = "/{userId}")
//	public String detail(Model model, @PathVariable Long userId){
//		// 用户信息
//		User user = userService.getById(userId);
//		model.addAttribute("user", user);
//		
//		// 分配角色
//		List<Role> roles = userRoleService.listByUserId(user.getUserId(), StatusEnum.NORMAL.getStatus());
//		model.addAttribute("roles", roles);// 用户权限
//		
//		return "/modules/admin/admin_user_message";
//	}
//	
//	/**
//	 * PUT 启用/冻结管理员
//	 * @return
//	 */
//	@ApiOperation(value = "启用/冻结管理员", notes = "根据url管理员ID启动/冻结管理员")
//	@RequiresPermissions("administrator:list:audit")
//	@PutMapping(value = "/{userId}/audit")
//	@ResponseBody
//	public Object audit(@PathVariable("userId") Long userId) {
//		AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
//		if (authorizingUser != null) {
//			Integer count = userService.updateStatus(userId);
//			return new CmsResult(CommonReturnCode.SUCCESS, count);
//		} else {
//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
//		}
//	}
//	
//	/**
//	 * DELETE 删除管理员
//	 * @return
//	 */
//	@ApiOperation(value = "删除管理员", notes = "根据url管理员ID删除管理员")
//	@RequiresPermissions("administrator:list:delete")
//	@DeleteMapping(value = "/{userId}")
//	@ResponseBody
//	public Object delete(@PathVariable("userId") Long userId) {
//		AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
//		if (authorizingUser != null) {
//			Integer count = userService.deleteByUserId(userId);
//			return new CmsResult(CommonReturnCode.SUCCESS, count);
//		} else {
//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
//		}
//	}
//	

//	/**
//	 * GET 管理员登录日志列表
//	 * @return
//	 */
//	@ApiOperation(value = "管理员登录日志列表", notes = "根据分页信息/搜索内容查询管理员登录日志列表")
//	@RequiresPermissions("administrator:list:view")
//	@GetMapping(value = "/{userId}/logs")
//	@ResponseBody
//	public Object listLogs(@PathVariable("userId") Long userId, PageInfo pageInfo,
//			@RequestParam(required = false, value = "search") String search) {
//		AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
//
//		if (authorizingUser != null) {
//			// 用户日志
//			BasePageDTO<UserLoginLog> basePageDTO = userLoginLogService.listByUserId(userId, pageInfo, search);
//			return new CmsPageResult(basePageDTO.getList(), basePageDTO.getPageInfo().getTotal());
//		} else {
//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
//		}
//	}
//	
//	/**
//	 * GET 创建管理员页面
//	 * @return
//	 */
//	@ApiOperation(value = "创建管理员页面", notes = "创建管理员页面")
//	@RequiresPermissions("administrator:list:create")
//	@GetMapping(value = "/create")
//	public String getInsertPage(Model model) {
//		// 用户权限
//		List<Role> roles = roleService.listBySataus(StatusEnum.NORMAL.getStatus());
//		model.addAttribute("roles", roles);
//
//		// 组织列表
//		List<Organization> organizations = organizationService.listBySataus(StatusEnum.NORMAL.getStatus());
//		model.addAttribute("organizations", organizations);
//
//		return "/modules/admin/admin_user_create";
//	}
//	
//	/**
//	 * POST 创建管理员
//	 * @return
//	 */
//	@ApiOperation(value = "创建管理员", notes = "创建管理员")
//	@RequiresPermissions("administrator:list:create")
//	@PostMapping(value = "")
//	@ResponseBody
//	public Object insert(User user, @RequestParam(required = false, value = "roleId") String[] roleIds) {
//		if (!RegexUtils.isEmail(user.getEmail())) {
//			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的电子邮箱!");
//		}
//		if (!RegexUtils.isTelephone(user.getTelephone())) {
//			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的手机号码!");
//		}
//
//		AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
//		if (authorizingUser != null) {
//			try {
//				// 创建用户及插入角色记录
//				Integer count = userService.insertUser(user, roleIds, authorizingUser.getUserName());
//				return new CmsResult(CommonReturnCode.SUCCESS, count);
//			} catch (ValidateException e) {
//				logger.error(e.getMessage(), e);
//				return new CmsResult(e.getCode(), e.getMessage());
//			}
//		} else {
//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
//		}
//	}
//	
//	/**
//	 * GET 更新管理员页面
//	 * @return
//	 */
//	@ApiOperation(value = "更新管理员页面", notes = "更新管理员页面")
//	@RequiresPermissions("administrator:list:edit")
//	@GetMapping(value = "/{userId}/edit")
//	public String getUpdatePage(Model model, @PathVariable("userId") Long userId) {
//		// 用户信息
//		User user = userService.getById(userId);
//		model.addAttribute("user", user);
//
//		// 用户权限
//		List<Role> roles = roleService.listBySataus(StatusEnum.NORMAL.getStatus());
//		model.addAttribute("roles", roles);
//
//		// 组织列表
//		List<Organization> organizations = organizationService.listBySataus(StatusEnum.NORMAL.getStatus());
//		model.addAttribute("organizations", organizations);
//
//		// 分配角色
//		List<Role> userRoles = userRoleService.listByUserId(user.getUserId(), StatusEnum.NORMAL.getStatus());
//		model.addAttribute("userRoles", userRoles);
//
//		return "/modules/admin/admin_user_update";
//	}
//	
//	/**
//	 * PUT 更新管理员信息
//	 * @return
//	 */
//	@ApiOperation(value = "更新管理员信息", notes = "根据url管理员ID来指定更新对象,并根据传过来的管理员信息来更新管理员信息")
//	@RequiresPermissions("administrator:list:edit")
//	@PutMapping(value = "/{userId}")
//	@ResponseBody
//	public Object update(User user, @PathVariable("userId") Long userId,
//			@RequestParam(required = false, value = "roleId") String[] roleIds) {
//		if (!RegexUtils.isEmail(user.getEmail())) {
//			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的电子邮箱!");
//		}
//		if (!RegexUtils.isTelephone(user.getTelephone())) {
//			return new CmsResult(CommonReturnCode.FAILED.getCode(), "请输入正确的手机号码!");
//		}
//
//		AuthorizingUser authorizingUser = SingletonLoginUtils.getUser();
//		if (authorizingUser != null) {
//			// 更新用户及角色记录
//			Integer count = userService.updateUser(user, roleIds, authorizingUser.getUserName());
//			return new CmsResult(CommonReturnCode.SUCCESS, count);
//		} else {
//			return new CmsResult(CommonReturnCode.UNAUTHORIZED);
//		}
//	}
//}
